package org.hot100_6.leetcode33;

public class Solution {

    public static void main(String[] args) {
        int [] nums = {3,1};
        int search = search(nums, 1);
        System.out.println(search);
    }

    public static int search(int[] nums, int target) {

        int n = nums.length;
        int left = 0;
        int right = n-1;

        while (left<=right){
            int mid = (left+right)>>>1;

            if (nums[mid]==target){
                return mid;
            }
            //前半段有序
            if (nums[mid]>=nums[left]){
                if (nums[left]<=target && target<nums[mid]){
                    right = mid-1;
                }else {
                    left = mid+1;
                }
            }else {
            //后半段有序
                if (nums[mid]<target && target<=nums[right]){
                    left = mid+1;
                }else {
                    right = mid-1;
                }
            }

        }

        return -1;
    }
}
